<?php
namespace app\admin\controller;

use app\index\model\Jianlis;
use app\index\model\Jianlisqz;
use app\index\model\Job;
use app\index\model\Users;
use think\Db;
use app\common\controller\AdminBase;

/**
* 职位管理
*/
class Toudi extends AdminBase
{
	
	protected function _initialize()
	{
		parent::_initialize();
	}
	public function index(){
        //职位投递
        $mJob = new Job();
        $mToudi = new \app\index\model\Toudi();
        $mUsers = new Users();
        $mJianlis = new Jianlis();
        $mJianlisqz = new Jianlisqz();
        //投递按时间排序的列表
        $lists = $mToudi->order('add_time desc')->paginate(15);
        foreach ($lists as &$value) {
            //投递的职位信息
            $value['jobdata'] = $mJob->where(['jobid'=>$value['jobid']])->field('jobid,jobname')->find();
            //当投递简历为兼职简历时
            if ($value['type']==1){
                $value['userdata'] = $mJianlis->where(['id'=>$value['jlid']])->field('id,name')->find();
            }else{
                //当投递简历为全职职简历时
                $value['userdata'] = $mJianlisqz->where(['id'=>$value['jlid']])->field('id,name')->find();
            }
        }
//        return $this->fetch('zw_list',['lists'=>$lists]);
        // $res = Db::table('hs_jianlis')
        //    ->alias('u')
        //    ->join('hs_jianli j','u.title = j.tid')
        //    ->where('openid',$openid)
        //    ->find();
        // if ($res) {
        //     $res['content'] = json_decode($res['content'],true);
        //     $res['title'] = json_decode($res['title'],true);
        //     $this->assign('user_data',$res);
        //     return $this->fetch('index');
        // }else{
        //     return $this->fetch('index/search_jl');
        // }
//        $list = Db::table('hs_toudi')
//            ->alias('td')
//            ->join('hs_job job','td.jobid = job.jobid')
//            ->join('hs_jianlis jl','td.openid = jl.openid')
//            ->field('job.jobname,jl.name,td.add_time,jl.id,job.jobid')
//            ->order('td.add_time desc')
//            ->paginate(15);
            // ->select();
            // echo "<pre>";
            // var_dump($list);
            // exit();
		// $list = db('toudi')->join('hs_job',) ->order('add_time desc')->paginate(15);
		return $this->fetch('index',['list'=>$lists]);
	}
	public function edit($id){
        $res = db('jianlis')->find($id);
        $res['content'] = json_decode($res['content'],true);
		return $this->fetch('edit',['rows'=>$res]);
	}
	/*
	 * 更新'0'或'1'
	 */
	public function flag($id){
        if (request()->isPost()) {
            $data = input('post.');
            if (db('jianlis')->where(['id' => $id])->update($data) !== false) {
                $this->success('更新成功');
            } else {
                $this->error('更新失败');
            }
        }
    }
}
